<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['PlaceOrder'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                下单 &nbsp;&nbsp;《商品名称:&nbsp;&nbsp;{{ baTable.form.items!.name }}》 &nbsp;&nbsp;&nbsp; 《商品单位:&nbsp;&nbsp;{{ baTable.form.items!.unit }}》
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @submit.prevent=""
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                >
                    <FormItem 
                        label="购买链接" 
                        type="remoteSelect" 
                        v-model="baTable.form.items!.goods_url_id" 
                        prop="goods_url_id" 
                        :input-attr="{ 
                            params: { isTree: true, treeAll: true }, 
                            pk: 'id', 
                            field: 'note', 
                            'remote-url': '/system/daily.GoodsAddress/index?id=' + baTable.form.items!.id,
                        }" 
                        placeholder="请选择购买链接" 
                    />
                    <FormItem :label="t('购买数量')" type="string" v-model="baTable.form.items!.num" prop="num" />
                    <FormItem :label="t('出售总价')" type="number" v-model="baTable.form.items!.sell_total_price" prop="sell_total_price" />
                    <FormItem :label="t('采购总价')" type="number" v-model="baTable.form.items!.buy_total_price" prop="buy_total_price" />
                    <!-- <FormItem :label="t('收货地址')" type="number" v-model="baTable.form.items!.num" prop="address_id" /> -->
                    <FormItem
                        label="付款方式"
                        class="pay-type"
                        type="radio"
                        v-model="baTable.form.items!.pay_type"
                        :input-attr="{ size: 'default' }"
                        :data="{ childrenAttr: { border: true }, content: { '0': '对公账户', '1': '现金' } }"
                    />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('立即下单') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { FormInstance, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'

const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

interface Props {
    place_order: object
}
const props = defineProps<Props>()

</script>

<style scoped lang="scss"></style>
